package cn.javadog.ss.spring.tx;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.Assert;

/**
 * @author 余勇
 * @date 2019年11月25日 18:17:00
 */
public class TxBootstrap {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(JdbcConfig.class);
		JdbcDao jdbcDao = applicationContext.getBean(JdbcDao.class);

		String key = getCityTime();
		try {
			jdbcDao.testTxWithException(key);
		}catch (RuntimeException r){
			System.out.println("捕捉到运行时异常，检查是否插入成功");
			boolean exist = jdbcDao.existCityTime(key);
			Assert.isTrue(!exist, "回滚失败！请检查逻辑");
		}

	}

	public static String getCityTime(){
		return "HZ" + System.currentTimeMillis();
	}


}
